package net.bwie.realtime.dy.dwd.log.funcation.zl.messagealterfuncation;

import net.bwie.realtime.dy.dwd.log.bean.TikTokBean;
import org.apache.flink.api.common.functions.AggregateFunction;

/**
 * @ClassName：MessageCountAggregator
 * @Author: ZddddQ
 * @Date: 2025/5/28 14:29
 * @Description: 必须描述类做什么事情, 实现什么功能
 */
public class MessageCountAggregator
        implements AggregateFunction<TikTokBean, Integer, Integer> {

    @Override
    public Integer createAccumulator() {
        return 0;  // 初始计数器为0
    }

    @Override
    public Integer add(TikTokBean bean, Integer accumulator) {
        // 每条消息触发计数器+1
        return accumulator + 1;
    }

    @Override
    public Integer getResult(Integer accumulator) {
        // 直接返回最终计数
        return accumulator;
    }

    @Override
    public Integer merge(Integer a, Integer b) {
        // 合并并行任务的结果
        return a + b;
    }
}
